<#include "macro_.ftl">
package ${packageCode}.${moduleMapperKey}.validator;

import lombok.NonNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import ${packageCode}.${moduleMapperKey}.service.${moduleMapperKey?cap_first}Service;

import ${packageCode}.${moduleMapperKey}.dto.${entityMapper.code}Dto;

/**
 * <@defaultIfBlank str="${entityMapper.remarks!}" defaultSt="${entityMapper.code!}"/>
 *
 * @author ${author!'yaoht'}
 * 
 */
@Component(${entityMapper.code}Validator.BEAN_ID)
public class ${entityMapper.code}Validator implements Validator {
	/**
	 * spring bean id
	 */
	public static final String BEAN_ID = "${packageCode}.${moduleMapperKey}.validator.${entityMapper.code}Validator";

	/**
	 * ${businessMapper.name!businessCode}服务
	 */
	@Qualifier(${moduleMapperKey?cap_first}Service.BEAN_ID)
	@Autowired(required = false)
	private ${moduleMapperKey?cap_first}Service ${moduleMapperKey}Service;
	
	@Override
	public boolean supports(@NonNull Class<?> clazz) {
		return ${entityMapper.code}Dto.class.equals(clazz);
	}
	
	@Override
	public void validate(@NonNull Object target, @NonNull Errors errors) {
		// ${entityMapper.code}Dto ${entityMapper.code?uncap_first} = (${entityMapper.code}Dto) target;
		// 
		// if (StringUtils.isBlank(${entityMapper.code?uncap_first}.getCode())) {
		// 	errors.reject("${entityMapper.code?uncap_first}.code.required", "编号不能为空");
		// }
	}
}
